package servlet.index;

import com.google.gson.Gson;
import dao.ProductTypeDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryClothingTypeServlet", value = "/QueryClothingTypeServlet")
public class QueryClothingTypeServlet extends HttpServlet {
    private ProductTypeDao dao = new ProductTypeDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        final String name = request.getParameter("name");
        final List<Map<String, Object>> clothingType = dao.findClothingType(name);
        final String json = new Gson().toJson(clothingType);
        response.getWriter().append(json);
    }
}
